import { App, createApp } from 'vue';
import { createPinia } from 'pinia';
import AppPage from './App.vue';
import { setupRouter } from './router';
import './style.css';

// createApp(App).mount('#app')

async function startApp() {
  console.log('Starting app...');
  const app = createApp(AppPage);
  const pinia = createPinia();
  app.use(pinia);
  await setupRouter(app);
  await loadPlugins(app);
  app.mount('#app');
}

async function loadPlugins(app: App<Element>) {
  const plugins = import.meta.glob('./plugins/*.ts');
  for (const path in plugins) {
    // console.log('Loading plugin: ' + path)
    const plugin = (await plugins[path]()) as any;
    app.use(plugin.default);
  }
}

startApp();
